from django.db import models

# Create your models here.

class College(models.Model):
    '''学院'''
    colid = models.AutoField(primary_key=True)
    intro = models.CharField(max_length=255,default='',null=True)
    colname = models.CharField(max_length=20,unique=True)

    def __str__(self):
        return self.colname

    class Meta:
        db_table = 'tb_college'

class Grade(models.Model):
    '''班级'''
    gradeid = models.CharField(primary_key=True,max_length=10)
    college = models.ForeignKey(to='College',on_delete=models.PROTECT,db_column='colid')

    class Meta:
        db_table = 'tb_grade'

class Student(models.Model):
    '''学生'''
    stuno = models.AutoField(primary_key=True)
    stuname = models.CharField(max_length=12)
    tel = models.CharField(max_length=20,unique=True)
    gender = models.BooleanField(default=True)
    age = models.IntegerField()
    grade = models.ForeignKey(to='Grade',on_delete=models.PROTECT,db_column='gradeid')

    class Meta:
        db_table = 'tb_student'